import 'package:any_reader/public.dart';

import '../provider/export.dart';
import 'export.dart';

class RetrievalModel extends ViewStateRefreshListModel {
  ThemeModel themeModel;
  RetrievalModel(this.themeModel);

  List<Map<String, dynamic>> bookTypeList = [
    {"id": "全部", "name": "全部"}
  ];

  List<Map<String, dynamic>> bookStatusList = [
    {"id": "0", "name": "全部"},
    {"id": "1", "name": "连载中"},
    {"id": "2", "name": "完本"},
  ];
  List<Retrieval> hot = [];
  int ruleIndex = 0;
  String searchKey = "";
  int pageSize = 20;
  String bookType = "全部";
  String bookStatus = "0";
  bool finish = false;
  bool loading = false;
  @override
  initData() async {
    // TODO: implement iniData
    FlutterStatusbarManager.setColor(themeModel.customThemeData.mainColor);
    setBusy(true);
    bookTypeList = await RetrievalService.getTypeList();
    await loadMore();
    print(bookTypeList);
    setBusy(false);
    notifyListeners();
  }

  setBookType(int index) {
    bookType = bookTypeList[index]['id'];
    notifyListeners();
    refresh(init: true);
  }

  setBookStatus(int index) {
    bookStatus = bookStatusList[index]['id'];
    notifyListeners();
    refresh(init: true);
  }

  @override
  refresh({bool init = false}) {
    // TODO: implement refresh
    setBusy(true);
    return super.refresh();
  }

  @override
  Future<List> loadData({int pageNum}) async {
    // TODO: implement loadData
    List<Book> _list;
    loading = true;
    _list = await BookService.getRetrieval(bookType, bookStatus, page: pageNum);
    setBusy(false);
    print("load Data");
    loading = false;
    return _list;
  }
}
